package com.aps.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.aps.entity.ResultEntity;
import com.aps.entity.domain.dish.DishInterval;
import com.aps.entity.domain.dish.DishTypeSeq;
import com.aps.page.BaseQuery;
import com.aps.service.IDishIntervalService;
import com.aps.service.rep.DishTypeSeqRep;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author liaoguangan
 * @description <>
 * @date 2018/4/9 15:55
 */
@RestController
@RequestMapping("/manage-api")
@Api(value = "manage-dish-type-interval-api", description = "菜品类别间隔时间管理接口")
public class DishTypeIntervalApi {

    /////////////////////菜品类别///////////////////////

    @Autowired
    private DishTypeSeqRep dishTypeSeqRep;

    @Autowired
    private IDishIntervalService dishIntervalService;

    @RequestMapping(value = "/dish-types", method = RequestMethod.GET)
    @ApiOperation("获取菜品类别")
    public ResultEntity listDishTypes() {
        return new ResultEntity(dishTypeSeqRep.findAllByOrderBySequenceAsc());
    }

    @RequestMapping(value = "/dish-types", method = RequestMethod.POST)
    @ApiOperation("更新菜品类别顺序")
    public ResultEntity listDishTypes(@RequestBody List<DishTypeSeq> seqs) {
        return new ResultEntity(dishTypeSeqRep.save(seqs));
    }

    @RequestMapping(value = "/list-interval", method = RequestMethod.POST)
    @ApiOperation("查询菜品间隔时间列表")
    public ResultEntity listInterval(@RequestBody BaseQuery baseQuery) {
        return new ResultEntity(dishIntervalService.list(baseQuery));
    }

    @RequestMapping(value = "/interval/{id}", method = RequestMethod.DELETE)
    @ApiOperation("删除菜品间隔时间")
    public ResultEntity removeInterval(@PathVariable("id") String id) {
        dishIntervalService.remove(id);
        return new ResultEntity(true);
    }

    @RequestMapping(value = "/interval", method = RequestMethod.POST)
    @ApiOperation("增加菜品间隔时间")
    public ResultEntity addInterval(@RequestBody DishInterval dishInterval) {
        return new ResultEntity(dishIntervalService.add(dishInterval));
    }

    @RequestMapping(value = "/interval", method = RequestMethod.PUT)
    @ApiOperation("修改菜品间隔时间")
    public ResultEntity updateInterval(@RequestBody DishInterval dishInterval) {
        return new ResultEntity(dishIntervalService.update(dishInterval));
    }

    @RequestMapping(value = "/interval/{id}", method = RequestMethod.GET)
    @ApiOperation("查询菜品间隔时间详情")
    public ResultEntity detailInterval(@PathVariable("id") String id) {
        return new ResultEntity(dishIntervalService.detail(id));
    }
}
